﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public class ConfigHelper
    {
        /// <summary>
        /// 周一学习小时数
        /// </summary>
        public static int MondayMinutes
        {
            get
            {
                return ReadAppSettingsValue("MondayMinutes", 30);
            }
        }

        /// <summary>
        /// 周二学习小时数
        /// </summary>
        public static int TuesdayMinutes
        {
            get
            {
                return ReadAppSettingsValue("TuesdayMinutes", 30);
            }
        }

        /// <summary>
        /// 周三学习小时数
        /// </summary>
        public static int WednesdayMinutes
        {
            get
            {
                return ReadAppSettingsValue("WednesdayMinutes", 30);
            }
        }

        /// <summary>
        /// 周四学习小时数
        /// </summary>
        public static int ThursdayMinutes
        {
            get
            {
                return ReadAppSettingsValue("ThursdayMinutes", 30);
            }
        }

        /// <summary>
        /// 周五学习小时数
        /// </summary>
        public static int FridayMinutes
        {
            get
            {
                return ReadAppSettingsValue("FridayMinutes", 30);
            }
        }

        /// <summary>
        /// 周六学习小时数
        /// </summary>
        public static int SaturdayMinutes
        {
            get
            {
                return ReadAppSettingsValue("SaturdayMinutes", 30);
            }
        }

        /// <summary>
        /// 周日学习小时数
        /// </summary>
        public static int SundayMinutes
        {
            get
            {
                return ReadAppSettingsValue("SundayMinutes", 30);
            }
        }

        /// <summary>
        /// 读取AppSettings
        /// </summary>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        private static int ReadAppSettingsValue(string key, int defaultValue)
        {
            int value;
            if (int.TryParse(ConfigurationManager.AppSettings[key], out value) == false)
            {
                value = defaultValue;
            }

            return value;
        }
    }
}
